package CPOO;

import ij.ImagePlus;
import ij.process.ByteProcessor;
import ij.process.ColorProcessor;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ClaheInterface implements  AlgorithmInterface {
		
	ImageProcessor processor;
	ImagePlus image;
	Clahe algorithm;
	
	public ClaheInterface()
	{
		algorithm= new Clahe();
	};
	
	public String getName() {
		
		return "Clahe";
	};

	public BufferedImage process(File f)
	{
		Image im;
		try 
		{
			im = ImageIO.read(f);
			processor=new ColorProcessor(im);
			image= new ImagePlus("processed file",processor);
			
			Clahe.run(image);
		
			
			return processor.getBufferedImage();	
		} catch (IOException e) 
		{
	
			e.printStackTrace();
			return null;
		}
		
	};


	public static  File writeImage(BufferedImage im, String name,String path )
	{
		 File file;
		try {
		    // retrieve image
			if(path==null)
				file= new File(name);
			else
				file=new File(path+ name);
		    ImageIO.write(im, "png", file);
		    return file;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

}
